package com.fireXXX.job.analysis.dynproxy.util.http.valid;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @description: TODO
 * @throws:
 * @author: zhuangzhang2
 * @date: 2020/04/28 11:09
 */
@Configuration
public class ValidRestTemplateConfig {

    @Value("${rest.timeout:5000}")
    private int timeout;

    @Bean("validRestTemplate")
    public RestTemplate validRestTemplate() {
        //设置超时
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(timeout);
        requestFactory.setReadTimeout(timeout);

        return new RestTemplate(requestFactory);
    }

}